"""
首先在浏览器端使用账号和密码登录QQ空间，然后记录下 cookie，最后将 cookie 封装在 headers 中，然后使用爬虫程序访问。
"""

import urllib.request

# get 请求
# api 接口
get_url = 'https://user.qzone.qq.com/976693405/infocenter?via=toolbar'

headers = {
	'cookie':'tvfe_boss_uuid=8fdef49bd4501f9f; pgv_pvid=1915638620; eas_sid=8116H1o00130U458W0g9o1K3x4; sd_userid=12961610105427167; sd_cookie_crttime=1610105427167; pac_uid=0_94c846ca5322a; LW_sid=U106A1Z0E3K384T3V3Q7t3o9I9; LW_uid=T176W1I0F3F3n493c3q7u4F0o2; ptui_loginuin=976693405; RK=tVI8aUhfWg; ptcz=57a88afa3a69e1ba403190580e8a5571f5f5cffec02a0533c60bbb57325ec097; pgv_info=ssid=s5359432105; _qpsvr_localtk=0.7256847809366289; uin=o0976693405; skey=@nDeOYmbNB; p_uin=o0976693405; pt4_token=HViLdFxopN5ILnegkuMcWSr9b*zgYOuEmrStKvhcxEw_; p_skey=Mejfkb67f9yK4JLPqwECg3DrxG9xFcYERbsA7a*7ZvA_; Loading=Yes; qz_screen=1366x768; 976693405_todaycount=0; 976693405_totalcount=0; QZ_FE_WEBP_SUPPORT=1; cpu_performance_v8=15; verifysession=h01f88eb612fcf3c536985ce1a6b33fc2271752f36660eeb5f2fd6e182bd5da638e320984a8b9f07896; welnewuser=1',
	'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',

}

request = urllib.request.Request(url=get_url,headers=headers)
response = urllib.request.urlopen(request)
resp_data = response.read().decode('utf-8')
print(resp_data)

with open('QQ空间.html','w',encoding='utf-8') as file:
	file.write(resp_data)


